package action;

import Impl.adminDaoImpl;
import entity.Admin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ShowAdmin")
public class ShowAdmin extends HttpServlet {
    adminDaoImpl adminDao = new adminDaoImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("------------正在执行ShowAdmin----------");
        request.setCharacterEncoding("utf-8");
        int pageNow = 0;
        if(request.getParameter("pageNow") == null) {
            pageNow = 1;
        }else {
            pageNow = Integer.parseInt(request.getParameter("pageNow"));
        }
        //       获取所有用户信息
        List<Admin> admins =adminDao.findAdminByPages(pageNow);
        List<Admin> adminList=adminDao.findAllAdmin();
        int allcount = adminList.size();
        int allpage;
        if(allcount % 5 == 0){
            allpage=allcount / 5;
        }
        else{
            allpage=allcount / 5 + 1;
        }
        request.setAttribute("allcount",allcount);
        request.setAttribute("allpage", allpage);
        request.setAttribute("pageNow", pageNow);
        request.setAttribute("adminList",admins);
        request.getRequestDispatcher("/admin-list.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
